<?php
/**
 * @file
 * Retrieves the current user's Facebook 'User ID' according to Facebook's
 * 'Automatic Authentication' model.
 *
 * Usage:
 *  - A page that wants to retrieve the current user's Facebook 'User ID' should
 *    include/require this page once and only once.
 *  - Also see 'js_params_get.php'.
 *
 * Parameter(s):
 *  - $PATH_COMMON : Relative path from the calling page to the 'common'
 *                   directory (e.g. '../common/').
 *
 * Global variable(s) set:
 *  - $fb_uid : The current user's Facebook 'User ID'.
 *
 * Global variable(s) unset:
 *  - None.
 *
 * Exception(s):
 *  - Throws an 'Exception' object if retreival of the current user's Facebook
 *    'User ID' fails.
 *
 * This file includes/requires:
 *  - h_facebook.php
 *  - fb_facebook.php
 */

// header file(s) ==============================================================
require_once $PATH_COMMON . "php/h_facebook.php";


// global variable(s) ==========================================================
//! The current user's Facebook 'User ID'.
$fb_uid = null;


// implementation ==============================================================
// create facebook object
require_once $PATH_COMMON . "php/fb_facebook.php";

if (false == isset($fb_uid)) {
  // retreive facebook user id from 'fb_sig_canvas_user'
  $fb_uid = $fb->get_canvas_user();
}
if (false == isset($fb_uid)) {
  // retreive facebook user id from 'fb_sig_user'
  $fb_uid = $fb->get_loggedin_user();
}
if (false == isset($fb_uid)) {
  // failed to retreive facebook user id, ask user to authorize application.
  $fb->require_login();
  //throw new Exception(FB_EX_MSG_USER_ID);
}
?>
